package com.yimi.yinhepda.adapter.RecycleAdapter;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.pda.ym.base.MultiTypeSupport;
import com.pda.ym.db.table.CarPlateTable;
import com.pda.ym.entity.bean.CarPlanTaskEntity;
import com.yimi.yinhepda.R;
import com.pda.ym.base.CommonRecycleAdapter;
import com.pda.ym.base.CommonViewHolder;
import com.yimi.yinhepda.db.dao.CarPlateTableDao;
import com.yimi.yinhepda.entity.bean.SealOrUnsealTaskEntity;
import com.yimi.yinhepda.utils.TransInformation;
import com.yimi.yinhepda.views.load_module.LoadUtil;

import java.util.List;

/**
 * 融合：解封任务列表适配器
 *
 * @author lj
 */

public class UnBlockingNewAdapter extends CommonRecycleAdapter<SealOrUnsealTaskEntity> {


    private Context mContext;
    private CommonViewHolder.onItemCommonClickListener mCommonClickListener;
    private View.OnClickListener onclick;
    private Button btnCarPlate;
    private EditText etCarNo;
    private Button btnSelectNextDept;

    public UnBlockingNewAdapter(Context context, List<SealOrUnsealTaskEntity> dataList,
                                CommonViewHolder.onItemCommonClickListener mCommonClickListener,
                                MultiTypeSupport<SealOrUnsealTaskEntity> multiTypeSupport,
                                View.OnClickListener onclick) {
        super(context, dataList, multiTypeSupport);
        this.mContext = context;
        this.mCommonClickListener = mCommonClickListener;
        this.onclick = onclick;
    }


    @Override
    public void bindData(CommonViewHolder holder, SealOrUnsealTaskEntity data, int position) {

        if (position == 0) {
            //第一项为搜索条件
            btnSelectNextDept = holder.getView(R.id.btn_selectNextDept);
            btnSelectNextDept.setOnClickListener(onclick);
            btnSelectNextDept.setHint("选择上一站");
            btnCarPlate = holder.getView(R.id.btn_carPlate);
            btnCarPlate.setOnClickListener(onclick);
            holder.getView(R.id.btn_down).setOnClickListener(onclick);
            //转换成大写
            etCarNo = holder.getView(R.id.et_carNo);
            etCarNo.setTransformationMethod(new TransInformation());
            holder.setText(R.id.tv_stationName, "上一站");

            if ("".equals(etCarNo.getText().toString().trim())) {
                //初始设置车牌
                List<CarPlateTable> carPlateTables = new CarPlateTableDao().getAllData();
                if (carPlateTables != null && !carPlateTables.isEmpty()) {
                    btnCarPlate.setText(carPlateTables.get(0).getCarPlate());
                }
            }

        } else {
            holder.setText(R.id.tv_taskNo, data.getTaskNo());
            holder.setText(R.id.tv_carNo, data.getVehNo());
            holder.setText(R.id.tv_routeLine, data.getVehLineName());
            if (data.getShift() == null) {
                holder.setText(R.id.tv_shift, "");
            } else {
                holder.setText(R.id.tv_shift, String.format("%s班次", LoadUtil.getShift(data.getShift())));
            }
            holder.setCommonClickListener(mCommonClickListener);

            holder.getView(R.id.ll_un_blocking).setSelected(data.isCheck());
        }
    }

    public Button getBtnSelectNextDept() {
        return btnSelectNextDept;
    }

    public void setBtnSelectNextDept(Button btnSelectNextDept) {
        this.btnSelectNextDept = btnSelectNextDept;
    }

    public Button getBtnCarPlate() {
        return btnCarPlate;
    }

    public void setBtnCarPlate(Button btnCarPlate) {
        this.btnCarPlate = btnCarPlate;
    }

    public EditText getEtCarNo() {
        return etCarNo;
    }

    public void setEtCarNo(EditText etCarNo) {
        this.etCarNo = etCarNo;
    }
}
